<!doctype html>


<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>const.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>





<div class="colmask rightmenu">
<div class="colleft">
    <div class="col1">
      <!-- Column 1 start -->

<div id="title">
       <span class="fn">const.js</span>
</div>

<div class="g-section g-tpl-75-25">
  <div class="g-unit g-first" id="description">
    <span class='nodesc'>No description.</span>
  </div>
  

        <div class="g-unit" id="useful-links">
          <div class="title">Useful links</div>
          <ol>
            <li><a href="local_closure_goog_string_const.js.source.html"><span class='source-code-link'>Source Code</span></a></li>
            <li><a href="http://code.google.com/p/closure-library/source/browse/local/closure/goog/string/const.js">Git</a></li>
          </ol>
        </div>
</div>

<h2 class="g-first">File Location</h2>
  <div class="g-section g-tpl-20-80">
    <div class="g-unit g-first">
      <div class="g-c-cell code-label">/goog/string/const.js</div>
    </div>
  </div>
<hr/>


  <h2>Classes</h2>
 <div class="fn-constructor">
        <a href="class_goog_string_Const.html">
          goog.string.Const</a><br/>
        <div class="class-details">Wrapper for compile-time-constant strings.

Const is a wrapper for strings that can only be created from program
constants (i.e., string literals).  This property relies on a custom Closure
compiler check that <code> goog.string.Const.from</code> is only invoked on
compile-time-constant expressions.

Const is useful in APIs whose correct and secure use requires that certain
arguments are not attacker controlled: Compile-time constants are inherently
under the control of the application and not under control of external
attackers, and hence are safe to use in such contexts.

Instances of this type must be created via its factory method
<code> goog.string.Const.from</code> and not by invoking its constructor.  The
constructor intentionally takes no parameters and the type is immutable;
hence only a default instance corresponding to the empty string can be
obtained via constructor invocation.

</div>
 </div>
      
<br/>

  <div class="legend">
        <span class="key publickey"></span><span>Public</span>
        <span class="key protectedkey"></span><span>Protected</span>
        <span class="key privatekey"></span><span>Private</span>
  </div>









<div class="section">
  <table class="horiz-rule">


  </table>
</div>




  <h2>Global Functions</h2>





<div class="section">
  <table class="horiz-rule">


     <tr class="even entry private">
       <td class="access"></td>






  <td>
    <a name="goog.string.Const.create__googStringSecurityPrivate_"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.string.Const.</span><span class="entryName">create__googStringSecurityPrivate_<span class="args">(<span class="arg">s</span>)</span>
        </span>
        &#8658; <span>!</span><span class="type"><a href="class_goog_string_Const.html">goog.string.Const</a></span>
      </div>


     <div class="entryOverview">
       Utility method to create Const instances.

     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">s</span>
        : <span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span>
        <div class="entryOverview">The string to initialize the Const object with.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<span>!</span><span class="type"><a href="class_goog_string_Const.html">goog.string.Const</a></span>&nbsp;
            The initialized Const object.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_string_const.js.source.html#line177">code &raquo;</a>
  </td>
     </tr>


     <tr class="odd entry public">
       <td class="access"></td>






  <td>
    <a name="goog.string.Const.from"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.string.Const.</span><span class="entryName">from<span class="args">(<span class="arg">s</span>)</span>
        </span>
        &#8658; <span>!</span><span class="type"><a href="class_goog_string_Const.html">goog.string.Const</a></span>
      </div>


     <div class="entryOverview">
       Creates a Const object from a compile-time constant string.

It is illegal to invoke this function on an expression whose
compile-time-contant value cannot be determined by the Closure compiler.

Correct invocations include,
<pre class="lang-js prettyprint">
  var s = goog.string.Const.from('hello');
  var t = goog.string.Const.from('hello' + 'world');
</pre>

In contrast, the following are illegal:
<pre class="lang-js prettyprint">
  var s = goog.string.Const.from(getHello());
  var t = goog.string.Const.from('hello' + world);
</pre>

TODO(user): Compile-time checks that this function is only called
with compile-time constant expressions.


     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">s</span>
        : <span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span>
        <div class="entryOverview">A constant string from which to create a Const.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<span>!</span><span class="type"><a href="class_goog_string_Const.html">goog.string.Const</a></span>&nbsp;
            A Const object initialized to stringConst.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_string_const.js.source.html#line157">code &raquo;</a>
  </td>
     </tr>


     <tr class="even entry public">
       <td class="access"></td>






  <td>
    <a name="goog.string.Const.unwrap"></a>


     <div class="arg">
       <img align="left" src="static/images/blank.gif">

        <span class="entryNamespace">goog.string.Const.</span><span class="entryName">unwrap<span class="args">(<span class="arg">stringConst</span>)</span>
        </span>
        &#8658; <span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span>
      </div>


     <div class="entryOverview">
       Performs a runtime check that the provided object is indeed an instance
of <code> goog.string.Const</code>, and returns its value.

     </div>


    <! -- Method details -->
    <div class="entryDetails">

      <div class="detailsSection">
        <b>Arguments: </b>






<table class="horiz-rule">
     
   <tr class="even">
     <td>
        <span class="entryName">stringConst</span>
        : <span>!</span><span class="type"><a href="class_goog_string_Const.html">goog.string.Const</a></span>
        <div class="entryOverview">The object to extract from.</div>
     </td>
   </tr>
  </table>
      </div>
   
      <div class="detailsSection">
        <b>Returns:</b>&nbsp;<span class="type"><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String">string</a></span>&nbsp;
            The Const object's contained string, unless the run-time
    type check fails. In that case, <code> unwrap</code> returns an innocuous
    string, or, if assertions are enabled, throws
    <code> goog.asserts.AssertionError</code>.
      </div>
  
    </div>
   
  </td>


  <td class="view-code">
     <a href="local_closure_goog_string_const.js.source.html#line114">code &raquo;</a>
  </td>
     </tr>


  </table>
</div>






      <!-- Column 1 end -->
    </div>

        <div class="col2">
          <!-- Column 2 start -->
          <div class="col2-c">
            <h2 id="ref-head">Directory string</h2>
            <div id="localView"></div>
          </div>

          <div class="col2-c">
            <h2 id="ref-head">File Reference</h2>
            <div id="sideFileIndex" rootPath="" current="/goog/string/const.js"></div>
          </div>
          <!-- Column 2 end -->
        </div>
</div>
</div>

</body>
</html>
